<template>
  <div class="bottom-left-chart-1">
    <div class="header-name">平台告警总数</div>
    <div class="details-value"><span>{{total}}</span>条</div>
    <dv-charts :option="option" />
  </div>
</template>

<script>
export default {
  props: {
    chartData: {
      type: Object,
      required: true
    }
  },
  name: 'BottomLeftChart1',
  data () {
    return {
      total: 0,
      option: {
        series: [
          {
            type: 'pie',
            data: [
              { name: '照明系统', value: 1, radius: ['30%', '33%'] },
              { name: '新风系统', value: 1, radius: ['32%', '35%'] },
              { name: '排风系统', value: 1, radius: ['31%', '37%'] },
              { name: '控制器系统', value: 1, radius: ['31%', '32%'] },
              { name: '空调系统', value: 1, radius: ['32%', '35%'] }
            ],
            outsideLabel: {
              labelLineEndLength: 20,
              formatter: '{percent}%\n{name}',
              style: {
                fill: '#fff'
              }
            }
          },
          {
            name: 'decoration ring',
            type: 'pie',
            data: [
              { value: 10, radius: ['50%', '53%'] }
            ],
            outsideLabel: {
              show: false
            },
            pieStyle: {
              fill: 'rgba(255, 255, 255, 0.2)'
            }
          },
          {
            name: 'decoration ring',
            type: 'pie',
            data: [
              { value: 10, radius: ['45%', '46%'] }
            ],
            outsideLabel: {
              show: false
            },
            pieStyle: {
              fill: 'rgba(255, 255, 255, 0.2)'
            }
          }
        ],
        color: ['#00c0ff', '#3de7c9', '#fff', '#00c0ff', '#3de7c9', '#fff']
      }
    }
  },
  watch: {
    chartData: {
      handler(newData) {
        if(newData != null && newData != undefined){
          const total = newData.fault.total
          const typeCounts = newData.fault.typeCounts
          if(total != undefined && total != null )
          {
            this.total  = total
          }
          if(typeCounts != undefined && typeCounts != null )
          {
            this.option =  {
              series: [
                {
                  type: 'pie',
                  data: this.getSeries(typeCounts),
                  outsideLabel: {
                    labelLineEndLength: 20,
                    formatter: '{percent}%\n{name}',
                    style: {
                      fill: '#fff'
                    }
                  }
                },
                {
                  name: 'decoration ring',
                  type: 'pie',
                  data: [
                    { value: 10, radius: ['60%', '65%'] }
                  ],
                  outsideLabel: {
                    show: false
                  },
                  pieStyle: {
                    fill: 'rgba(255, 255, 255, 0.2)'
                  }
                },
                {
                  name: 'decoration ring',
                  type: 'pie',
                  data: [
                    { value: 10, radius: ['45%', '46%'] }
                  ],
                  outsideLabel: {
                    show: false
                  },
                  pieStyle: {
                    fill: 'rgba(255, 255, 255, 0.2)'
                  }
                }
              ],
              color: ['#00c0ff', '#3de7c9', '#fff', '#00c0ff', '#3de7c9', '#fff']
            }
          }
        }
      },
      immediate: true,
      deep: true
    }
  },
  methods:{
    getSeries(typeCounts){
      const arr = []
      console.log(typeCounts)
      for(const typeCount of typeCounts){
        let name = typeCount.deviceName
        let value = typeCount.num
        let radius =[ '40%', '45%']
        arr.push({ name: name, value: value, radius: radius })
      }
      return arr
    }
  }
}
</script>

<style lang="scss">
.bottom-left-chart-1 {
  position: relative;

  .header-name {
    height: 150px;
    line-height: 150px;
    font-size: 20px;
    text-align: center;
  }

  .details-value {
    height: 40px;
    font-size: 30px;
    font-weight: bold;
    text-align: center;

    span {
      color: #00c0ff;
      font-size: 45px;
    }
  }

  .dv-charts-container {
    height: calc(100% - 190px);
  }

  .decoration-ring {
    position: absolute;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    border: 5px solid fade(#fefefe, 30);
    top: 190px;
    left: 50%;
    transform: translateX(-50%);
  }
}
</style>
